<template>
  <div>
    <n-card :bordered="false">
      <n-tabs type="card" animated :placement="top" @update:value="handleUpdateValue">
        <n-tab-pane name="1" tab="总后台">
          <General :columns="general" :userType="1" />
        </n-tab-pane>
        <n-tab-pane name="2" tab="单位账号"> <General :columns="unit" :userType="2" /> </n-tab-pane>
        <n-tab-pane name="3" tab="车间账号">
          <General :columns="workshop" :userType="3" />
        </n-tab-pane>
        <n-tab-pane name="4" tab="外部单位账号">
          <General :columns="externalUnit" :userType="4" />
        </n-tab-pane>
        <n-tab-pane name="5" tab="外部车间账号">
          <General :columns="externalWorkshop" :userType="5" />
        </n-tab-pane>
      </n-tabs>
    </n-card>
    <n-card :bordered="false" class="proCard"> </n-card>
  </div>
</template>

<script lang="ts" setup>
  import { h, reactive, ref } from 'vue';
  import { BasicTable, TableAction } from '@/components/Table';
  import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
  import { getUserList, addUser, delUser, edit } from '@/api/api';
  import { general, unit, workshop, externalWorkshop, externalUnit } from './columns';
  import { schemasUser, schemasUserModal } from '@/config/options';
  import { PlusOutlined } from '@vicons/antd';
  import { useRouter } from 'vue-router';
  import { type FormRules } from 'naive-ui';

  import { useMessage, useDialog } from 'naive-ui';
  import General from './components/General.vue';
  const placement = ref('top');
  const type = ref('card');
  const router = useRouter();
  const formRef: any = ref(null);
  const actionRef = ref();
  const formBtnLoading = ref(false);

  const formParams = reactive({
    name: '',
    role: null,
    droit: true,
  });
  const message = useMessage();
  const dialog = useDialog();

  const [register, { getFieldsValue }] = useForm({
    gridProps: { cols: '1 s:1 m:2 l:3 xl:4 2xl:4' },
    labelWidth: 80,
    schemas: schemasUser,
  });

  // 编辑账号
  const handleEdit = async (formRes) => {
    console.log(formRes);
    const data = await edit({ ...formRes, user_type: 1, unit: 2 }).then(() => {
      setSubLoading(false);
      closeModal();
      message.info('修改成功');
    });
  };
  // 滑块切换添加权限状态
  function handleChange(value: boolean) {
    console.log(value);
  }
  // 获取表格数据
  const loadDataTable = async (res, user_type) => {
    const data = await getUserList({ ...getFieldsValue(), ...res, user_type: user_type });
    console.log(data);
    return data;
  };

  function reloadTable() {
    actionRef.value.reload();
  }
  function handleReset(values: Recordable) {
    console.log(values);
  }
</script>

<style lang="less" scoped>
  :deep(.header) {
    border-radius: 50% !important;
  }
  .proCard {
    margin-top: 20px;
  }
</style>
